home *** CD-ROM | disk | FTP | other *** search
- /* SETVECT.C --- p. 670 */
- #include <stdio.h>
- #include <dos.h>
- #define TIMER_TICK 0x1c
- unsigned long tickcount = 0;
- void interrupt our_handler(void);
- main()
- {
- unsigned c;
- void interrupt (*old_handler)();
- unsigned intno = TIMER_TICK;
- old_handler = getvect(intno);
- /* Print out address of the old handler using the %p
- * format */
- printf("\nThe address of the old handler is: %Fp\n", old_handler);
- /* Install the new handler named our_handler
- * Disable interrupts when changing handler */
- disable();
- setvect(intno, our_handler);
- enable();
- printf("Installed new handler: %p\n", our_handler);
- printf("Hit Q to quit: ");
-
- while((c=getch()) != 'q'); /* Keep looping till 'q' */
- /* Reset vector and print the tickcounter. Again disable
- * interrupts when doing this. */
- disable();
- setvect(intno, old_handler);
- enable();
- printf("The tick counter is now: %ld\n", tickcount);
- }
- /*-------------------------------*/
- void interrupt our_handler()
- {
- /* Our handler simply increments a counter. But this
- * will be proof enough that the handler works because
- * we are not calling it explicitly in the main program
- * and the only way it get called is via INT 1Ch. */
- tickcount++;
- }